//
//  ExpertDetailsExpertAppraise.m
//
//  Created by 啊  on 16/5/10
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ExpertDetailsExpertAppraise.h"
#import "ExpertDetailsExpert.h"


NSString *const kExpertDetailsExpertAppraiseEaAppraise = @"eaAppraise";
NSString *const kExpertDetailsExpertAppraiseEId = @"eId";
NSString *const kExpertDetailsExpertAppraiseExpert = @"Expert";
NSString *const kExpertDetailsExpertAppraiseEaId = @"eaId";


@interface ExpertDetailsExpertAppraise ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ExpertDetailsExpertAppraise

@synthesize eaAppraise = _eaAppraise;
@synthesize eId = _eId;
@synthesize expert = _expert;
@synthesize eaId = _eaId;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.eaAppraise = [self objectOrNilForKey:kExpertDetailsExpertAppraiseEaAppraise fromDictionary:dict];
            self.eId = [[self objectOrNilForKey:kExpertDetailsExpertAppraiseEId fromDictionary:dict] doubleValue];
            self.expert = [ExpertDetailsExpert modelObjectWithDictionary:[dict objectForKey:kExpertDetailsExpertAppraiseExpert]];
            self.eaId = [self objectOrNilForKey:kExpertDetailsExpertAppraiseEaId fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.eaAppraise forKey:kExpertDetailsExpertAppraiseEaAppraise];
    [mutableDict setValue:[NSNumber numberWithDouble:self.eId] forKey:kExpertDetailsExpertAppraiseEId];
    [mutableDict setValue:[self.expert dictionaryRepresentation] forKey:kExpertDetailsExpertAppraiseExpert];
    [mutableDict setValue:self.eaId forKey:kExpertDetailsExpertAppraiseEaId];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.eaAppraise = [aDecoder decodeObjectForKey:kExpertDetailsExpertAppraiseEaAppraise];
    self.eId = [aDecoder decodeDoubleForKey:kExpertDetailsExpertAppraiseEId];
    self.expert = [aDecoder decodeObjectForKey:kExpertDetailsExpertAppraiseExpert];
    self.eaId = [aDecoder decodeObjectForKey:kExpertDetailsExpertAppraiseEaId];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_eaAppraise forKey:kExpertDetailsExpertAppraiseEaAppraise];
    [aCoder encodeDouble:_eId forKey:kExpertDetailsExpertAppraiseEId];
    [aCoder encodeObject:_expert forKey:kExpertDetailsExpertAppraiseExpert];
    [aCoder encodeObject:_eaId forKey:kExpertDetailsExpertAppraiseEaId];
}

- (id)copyWithZone:(NSZone *)zone
{
    ExpertDetailsExpertAppraise *copy = [[ExpertDetailsExpertAppraise alloc] init];
    
    if (copy) {

        copy.eaAppraise = [self.eaAppraise copyWithZone:zone];
        copy.eId = self.eId;
        copy.expert = [self.expert copyWithZone:zone];
        copy.eaId = [self.eaId copyWithZone:zone];
    }
    
    return copy;
}


@end
